package com.rongcheng.forfeature;

import android.text.TextUtils;
import android.text.method.MovementMethod;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.rongcheng.forfeature.stores.MessageStore;
import com.rongcheng.forfeature.stores.Store;
import com.squareup.otto.Subscribe;
/**
 * 主页
 * @author fengrongcheng
 * created at 16-11-8 上午11:16
 */
public class MainActivity extends BaseActivity {
    private Button mBtnTestForFlux;
    private TextView mTvOutput;
    private EditText mEdtInput;
    private SimpleDraweeView simpleDraweeView;


    @Override
    protected void doBeforeSetContentView() {

    }

    @Override
    protected int setContentViewID() {
        return R.layout.activity_main;
    }


    @Override
    protected Store getStore() {
        return store = new MessageStore();
    }

    @Override
    protected void initView() {
        mBtnTestForFlux = (Button) findViewById(R.id.btn_test_for_flux);
        mEdtInput = (EditText) findViewById(R.id.edt_input);
        mTvOutput = (TextView) findViewById(R.id.tv_output);
        mTvOutput.setMovementMethod(new ScrollingMovementMethod());

    }

    @Override
    protected void initData() {


    }

    @Override
    protected void setViewListener() {

        mBtnTestForFlux.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                actionCreator.sendMessage(!TextUtils.isEmpty(mEdtInput.getText().toString().trim()) ? mEdtInput.getText().toString().trim() : "edit is null");
            }
        });
    }

    @Subscribe
    public void onStoreChange(Store.StoreChangeEvent event) {
        render(store);
    }

    private void render(Store store) {
        mTvOutput.setText(((MessageStore) store).getMessage());
    }

}